<?php
/**
 * Created by PhpStorm.
 * User: HuangLuSen
 * Date: 2017/5/11
 * Time: 10:39
 */

namespace app\common\message\model;


use app\admin\model\Users;
use app\common\message\Message;
use app\common\model\Customer;
use think\Db;

class WechatMessage extends Message
{
    /**
     * 抽象类 不同的消息来重写这个方法 一得到不同的消息数据格式
     * @return mixed
     */
    public function combin_Data()
    {
        $data = $this->datas;
        $user = Users::where(['id'=>$data['userid'],'status'=>1,'weixinstatus'=>1])->field('id,openid')->find();
//        $senduser = Users::where(['id'=>$data['sendid'],'status'=>1])->with('depar')->field('id,username,depar_id')->find();
        if(isset($data['zjs'])){
            $senduser = Customer::where(['id'=>$data['sendid'],'status'=>1])->with('department')->field('id,username,bumen')->find();
            $str = "【{$senduser->department->sectionname}-{$senduser->username}】";
        }else{
            $senduser = Users::where(['id'=>$data['sendid'],'status'=>1])->with('depar')->field('id,username,depar_id')->find();
            $str = "【{$senduser->depar->name}-{$senduser->username}】";
        }

        $datas = [
            'touser'=>$user['openid'],//openid
            'template_id'=>config('admin.weixin.new_notice'),
            'url'=>$data['url'],
            'data'=>[
//                'first'=>['value'=>"【{$senduser->depar->name}-{$senduser->username}】".$data['first'],'color'=>'#173177'],
                'first'=>['value'=>$str.$data['first'],'color'=>'#173177'],
                'keyword1'=>['value'=> !empty($data['keyword1'])?$data['keyword1']:'','color'=>'#173177'],
                'keyword2'=>['value'=> !empty($data['keyword2'])?$data['keyword2']:'','color'=>'#173177'],
                'keyword3'=>['value'=> !empty($data['keyword3'])?$data['keyword3']:'','color'=>'#173177'],
                'keyword4'=>['value'=> !empty($data['keyword4'])?$data['keyword4']:'','color'=>'#F30808'],
                'keyword5'=>['value'=> !empty($data['keyword5'])?$data['keyword5']:'','color'=>'#173177'],
                'remark'=>['value'=>"感谢使用".config('admin.company.gos'),"color"=>'#173177'],
            ]
        ];
        return $datas;
    }
}